package com.baizhi.controller;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.entity.SexCount;
import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("selectAll")
    @ResponseBody
    public Map selectAll(String name, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit){
        Map map = new HashMap();
        PageInfo<User> info = userService.selectPaeg(name, page, limit);
        map.put("code",0);
        map.put("msg","");
        map.put("count",info.getTotal());
        map.put("data",info.getList());
        return map;
    }
    @RequestMapping("status")
    public void status(Integer id,Integer status){
        userService.status(id,status);
    }
    @RequestMapping("selectSexCount")
    @ResponseBody
    public List<SexCount> selectSexCount(){
        return userService.selectSexCount();
    }
    /**
    *查询用户注册的数量
    */
    @RequestMapping("selectRegiterCount")
    @ResponseBody
    public List<SexCount> selectRegiterCount(){
        List<SexCount> sexCounts = userService.selectRegisterCount(null, null);
        return sexCounts;
    }
    @RequestMapping("selectProvinceCount")
    @ResponseBody
    public List<Map> selectProvinceCount(){
        return userService.selectProvinceCount();
    }
    /**
     * 优化
     */
    @LogAnnotation(content = "数据可视化展示",type = "查询")
    @RequestMapping("selectAllCount")
    @ResponseBody
    public Map selectAllCount(){
        long start = System.currentTimeMillis();
        Map map = userService.selectAllCount();
        long end = System.currentTimeMillis();
        System.err.println(end - start +"毫秒");
        return map;
    }
    /**
     * 无优化
     */
    @RequestMapping("selectNo")
    @ResponseBody
    public Map selectNo(){
        long start = System.currentTimeMillis();
        Map map = userService.selectNo();
        long end = System.currentTimeMillis();
        System.err.println(end - start +"毫秒");
        return map;
    }
}
